(define counter (make-vector 1))

(define (between min max)
  (if (> min max)
      '()
      (cons min (between (+ min 1) max))))

(define (partitions-> min n l)
  (if (> min n)
      (if (= n 0)
	  (begin
	    (vector-set! counter 0 (+ (vector-ref counter 0) 1))
	    (print l))
	  #f)
      (for-each (lambda (k)
	          (partitions-> k (- n k) (cons k l)))
        (between min n))))

(define (partitions n)
  (display "partitions of ")
  (print n)
  
  (vector-set! counter 0 0)
  (partitions-> 1 n '())
  
  (display (vector-ref counter 0))
  (print " partitions!"))

(define main
  ;; should be 627
  (partitions 20))
